import cufflinks as cf
import plotly as py
import pandas as pd
import matplotlib as mpl
import plotly.graph_objects as go
import matplotlib.pyplot as plt
import seaborn as sns  # seaborn

mpl.rcParams['font.sans-serif'] = ['KaiTi']
mpl.rcParams['font.serif'] = ['KaiTi']
mpl.rcParams['axes.titlesize'] = 24 # fontsize 
mpl.rcParams['xtick.labelsize'] = 18 # fontsize 
mpl.rcParams['ytick.labelsize'] = 18 # fontsize 
mpl.rcParams['legend.fontsize'] = 18
# mpl.rcParams['legend.title_fontsize'] = 18 
mpl.rcParams['legend.loc'] = 'upper right'
zh_font = "simhei" # "MingLiU"#"SimSun"# "Microsoft JhengHei"#"DFKai-SB" "FangSong"#'DengXian'#'Microsoft YaHei'
plt.rcParams['font.sans-serif'] = [zh_font]  # 中文字体设置-黑体
plt.rcParams['axes.unicode_minus'] = False  # 解决保存图像是负号'-'显示为方块的问题
plt.rcParams['xtick.labelsize'] = 24  
plt.rcParams['ytick.labelsize'] = 24 
sns.set(font=zh_font)  # 解决Seaborn中文显示问题

# C-0 
def visualize_seaborn(file_out_png,file_out_svg,data_input, N, kind, info="全", figsize=(14,18), color_map="YlGnBu"):
    """
    生成数据可视化热点图png、svg两个格式
    """
    plt.figure(figsize=figsize)
    ax = sns.heatmap(data_input, cmap=color_map, annot=True, \
                     fmt="0.3f", linewidth =.5 )
    fig = ax.get_figure()
    fig.subplots_adjust(left=0.35)
    fig.savefig(file_out_png.format(N=N, kind=kind, info=info), dpi=300)
    fig.savefig(file_out_svg.format(N=N, kind=kind, info=info), dpi=300)

# C-1多个模型图生成
def visualize_range(全df,file_out_png,file_out_svg,N1,N2,kind):
    """循环生成全数据模型图
    根据输入的N值循环生成
    """
    for N in range(N1,N2):
        for kind in list(全df.columns): #['号_题', '号_集团']
            data = 全df.loc[N,kind]
            data.index.name = '提交作品'
            data.columns.name = '主题'
            visualize_seaborn(file_out_png,file_out_svg,data, N, kind)  #"coolwarm"


if __name__ == '__main__':
    visualize_seaborn()
    visualize_range()
            